<?php

namespace App\models;

use Illuminate\Database\Eloquent\Model;

class Idea extends Model
{
    protected $table = 'idea';
    protected $primaryKey = 'idea_id';
    public $timestamps = false;

    //查询所有意见
    public static function select()
    {
        return self::with(['user'])->get()->toArray();
    }

    //关联用户表
    public function user()
    {
        return $this->belongsTo('App\models\User','idea_user_id','user_id');
    }

    //修改意见状态
    public static function updates($idea_id,$status)
    {
        if($status==1)
        {
            $c=Idea::find($idea_id);
            $c->idea_status='0';
            return $c->save();
        }
        else
        {
            $c=Idea::find($idea_id);
            $c->idea_status='1';
            return $c->save();
        }
    }

    //删除用户意见
    public static function dele($id)
    {
        return self::destroy($id);
    }
}
